//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
/*
     -------------------------------------------------------------------
    |                                                                   |
    |    Queue Class                                                    |
    |    ===========================================================    |
    |    This Queue Class has been implemented with templates and       |
    |    the size is determined dynamically at initialization.          |
    |                                                                   |
    |    The actual amount of space allocated for the Queue will be     |
    |    one more element space than the defined maximum size. This     |
    |    is useful for implementing the Queue in a circular method.     |
    |                                                                   |
    |    To understand the circular implementation, think of the        |
    |    array as a circle. When you reach the end of the array, you    |
    |    wrap around to the beginning of the array.                     |
    |                                                                   |
    |    So, when an element is dequeued, the Queue doesn't shift.      |
    |    Instead, you updated an indicator of the start of the queue.   |
    |                                                                   |
     -------------------------------------------------------------------
*/

#ifndef __Queue_H__
#define __Queue_H__

//#include <stdio.h>
//#include <assert.h>

//#define _DBGQUEUE

//-------------------------------------------------
// Main structure of Queue Class:
//-------------------------------------------------

class Queue
{
public:
    Queue(int ElemSize=4, int MaxSize=32);
    ~Queue(void);

    int     Enqueue(const void *pElem); // Adds Item to Queue end
    int     Dequeue(/*Out*/void *pElem);// Returns Item from Queue
#if defined(_DBGQUEUE)
    void    Dump(void);
#endif

public:
    const int   ELEM_SIZ;
    const int   MAX_NUM;    // The actual spaces will be one more than this
    unsigned char *Data;    // The actual Data array
    int         Head,       // Numbered location of the head and tail
                Tail,       //
                Drops;      // element droped when queue FIFO is full
};

#endif /*__Queue_H__*/
